local scene = director:createScene()

function scene:setUp(event)
    dbg.print("sceneMenu:setUp")
		
	local scaleX = 320/director.displayWidth
	local scaleY = 480/director.displayHeight
	
	if (io.open("levelrecord.txt") == nil) then
	file = io.open("levelrecord.txt", "w")
	file:write("0".."\n")
	file:write("0".."\n")
	file:write("0".."\n")
	file:write("0".."\n")
	file:write("0".."\n")
	file:close()
	end
	
	local screen = director:createSprite(director.displayCenterX, director.displayCenterY, "img/screen.png")
	screen.xAnchor=0.5; 
	screen.y = director.displayCenterY + director.displayCenterY/4/scaleY
	screen.xScale=1/scaleX
	screen.yScale=1/scaleY
	
    local buttonGame = director:createSprite(director.displayCenterX, director.displayCenterY, "img/button.png")
	buttonGame.xAnchor=0.5; buttonGame.yAnchor=0.5
	buttonGame.y = director.displayCenterY + buttonGame.h/2/scaleY
	buttonGame.yScale=.6/scaleY; 
	buttonGame.xScale=1.1/scaleX;
	
	local labelGame = director:createLabel(director.displayCenterX, director.displayCenterY, "Game")
	labelGame.xAnchor=0.5; 
	labelGame.zOrder = buttonGame.zOrder
	labelGame. hAlignment="center"
	labelGame.y = buttonGame.y-10/scaleY
	labelGame.color = color.white
	labelGame.yScale = 1/scaleY
	labelGame.xScale = 1/scaleX
	
	local buttonScore = director:createSprite(director.displayCenterX, director.displayCenterY, "img/button.png")
	buttonScore.xAnchor=0.5; buttonScore.yAnchor=0.5
	buttonScore.y =  director.displayCenterY - buttonScore.h/3/scaleY
	buttonScore.yScale=.6/scaleY 
	buttonScore.xScale=1.1/scaleX
	
	local labelScore = director:createLabel(director.displayCenterX, director.displayCenterY, "Score")
	labelScore.xAnchor=0.5; 
	labelScore.zOrder = buttonScore.zOrder
	labelScore. hAlignment="center"
	labelScore.y = buttonScore.y-10/scaleY
	labelScore.color = color.white
	labelScore.yScale = 1/scaleY
	labelScore.xScale = 1/scaleX
	
	local buttonInstructions = director:createSprite(director.displayCenterX, director.displayCenterY, "img/button.png")
	buttonInstructions.xAnchor=0.5; buttonInstructions.yAnchor=0.5
	buttonInstructions.y =  director.displayCenterY - buttonInstructions.h/scaleY
	buttonInstructions.yScale=.6/scaleY; 
	buttonInstructions.xScale=1.1/scaleX;
	
	local labelInstructions = director:createLabel(director.displayCenterX, director.displayCenterY, "Instructions")
	labelInstructions.xAnchor=0.5;
	labelInstructions.zOrder = buttonGame.zOrder
	labelInstructions. hAlignment="center"
	labelInstructions.y = buttonInstructions.y-10/scaleY
	labelInstructions.color = color.white
	labelInstructions.yScale = 1/scaleY
	labelInstructions.xScale = 1/scaleX
	
	function buttonGame:touch(event)
		if (event.phase == 'began') then
			selectGame = "Game"
			system:sendEvent("moveToSceneGame")
		end
	end
	buttonGame:addEventListener('touch', buttonGame)

	function buttonInstructions:touch(event)
		if (event.phase == 'began') then
			system:sendEvent("moveToSceneInstructions")
		end
	end
	buttonInstructions:addEventListener('touch', buttonInstructions)
	
	function buttonScore:touch(event)
		if (event.phase == 'began') then
			system:sendEvent("moveToSceneScore")
		end
	end
	buttonScore:addEventListener('touch', buttonScore)
end

function scene:tearDown(event)
    dbg.print("sceneMenu:tearDown")
end

scene:addEventListener({"setUp", "tearDown"}, scene)

return scene  -- We must return the scene object!